﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace QuizzAdminData
{
    public static class SpelDB
    {
        public static List<Spel> GetSpellen()
        {
            List<Spel> spellen = new List<Spel>();

            SqlConnection conn = QuizzAdminDB.GetConnection();

            string selectStatement = "SELECT * FROM Spel";

            SqlCommand selectCmd = new SqlCommand(selectStatement, conn);

            try
            {
                conn.Open();
                SqlDataReader reader = selectCmd.ExecuteReader();
                while (reader.Read())
                {
                    Spel spel = new Spel();

                    spel.id = (int)reader["id"];

                    spellen.Add(spel);
                }

                reader.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return spellen;
        }
    }
}
